#include "WebHelper.h"

WebHelper::WebHelper(string type, string url, string version) {
	this->type = type;
	this->httpVersion = version;
	this->url = url;
}
WebHelper::~WebHelper(void) {

}
void WebHelper::AddOptions(string option) {
	this->options.push_back(option);
}
void WebHelper::AddCookies(string cookies) {
	this->cookies.push_back(cookies);
}
void WebHelper::ClearOptions(void) {
	this->options.clear();
}
void WebHelper::ClearCookies(void) {
	this->cookies.clear();
}
void WebHelper::SetContent(string cookies) {
	this->content = cookies;
}
void WebHelper::ClearContent(void) {
	this->content.clear();
}
void WebHelper::SetupRequest(void) {
	ostringstream ostr;
	this->requestBody.clear();
	ostr << this->type << " " << this->url << " " << this->httpVersion << "\r\n";
	for (int i = 0; i < options.size(); i++) {
		ostr << options[i] << "\r\n";
	}
	//Cookie
	if (!this->cookies.empty()) {
		ostr << "Cookie: ";
		for (int i = 0; i < cookies.size(); i++) {
			if (i < cookies.size() - 1)
				ostr << cookies[i] << "; ";
			else
				ostr << cookies[i];
		}
		ostr << "\r\n";
	}
	//Content-Length
	ostr << "Content-Length: " << this->content.size() << "\r\n";
	//Content
	ostr << "\r\n";
	ostr << this->content;
	this->requestBody = ostr.str();
	cout << ostr.str() << endl;
}